package top.igotcha.chapter.chapter4;

/**
 * @author Gotcha
 * @date 2021/3/8
 * @describe
 */
public class Volatile01 {
    //使用易变关键字
    volatile static Boolean run = true;
    public static void main(String[] args) throws InterruptedException {
        new Thread(()->{
            while (run) {
                //如果run为真，则一直执行
            }
        }).start();

        Thread.sleep(1000);
        System.out.println("改变run的值为false");
        run = false;
    }
}
